﻿#include <iostream>
#include <string>
using namespace std;
/* 对象结构型模式
1.意图
动态地给一个对象添加一些额外的职责。就增加功能来说，Decorator模式相比生成子类更为灵活
2.别名
包装器Wrapper
3.适用性
a.在不影响其他对象的情况下，以动态、透明的方式给单个对象添加职责
b.处理那些可以撤消的职责
c.当不能采用生成子类的方法进行扩充时。一种情况是，可能有大量独立的扩展，为支持每一种组合将产生大量的子类，使得子类数目呈爆炸
性增长。另一种情况可能是因为类定义被隐藏，或类定义不能用于生成子类。
*/
class AbstractComponet
{
public:
	virtual void Show() = 0;
	string pStr;
};

class MobilePhone :public AbstractComponet
{
public:
	MobilePhone()
	{
		this->pStr = "裸机";
	}
	void Show()
	{
		cout << this->pStr << endl;
	}
};
class AbstractDecorator :public AbstractComponet
{
public:
	virtual void Show() = 0;
protected:
	AbstractComponet* pBase;
};
//蓝牙
class Bluetooth :public AbstractDecorator
{
public:
	Bluetooth(AbstractComponet* pBase)
	{
		this->pBase = pBase;
	}
	void Show()
	{
		this->pStr = this->pBase->pStr + " 装饰了蓝牙";
		cout << this->pStr << endl;
	}
};
//手机壳
class Shell :public AbstractDecorator
{
public:
	Shell(AbstractComponet* pBase)
	{
		this->pBase = pBase;
	}
	void Show()
	{
		this->pStr = this->pBase->pStr + " 装饰了手机壳";
		cout << this->pStr << endl;
	}
};
/*
int main()
{
	MobilePhone* phone = new MobilePhone();
	phone->Show();
	Bluetooth* bluetooth = new Bluetooth(phone);
	bluetooth->Show();
	Shell* shell = new Shell(phone);
	shell->Show();
	bluetooth = new Bluetooth(shell);
	bluetooth->Show();
	delete phone;
	delete bluetooth;
	delete shell;
	return 0;
}
*/